<template>
  <el-carousel :interval="4000" type=card :height="bannerHeight+'px'">
    <el-carousel-item v-for="item in images" :key="item.id">
      <el-row>
        <el-col :span="24">
          <img ref="bannerHeight" :src="item.idView" class="banner_img" @load="imageLoad"/>
        </el-col>
      </el-row>
    </el-carousel-item>
  </el-carousel>
</template>

<script>
export default {
  name: "Carousel",
  data() {
    return {
      bannerHeight:'',
      images: [
        {id: 1, idView: require('@/assets/1.jpg')},
        {id: 2, idView: require('@/assets/2.jpg')},
        {id: 3, idView: require('@/assets/3.jpg')},
        {id: 4, idView: require('@/assets/4.jpg')},
        {id: 5, idView: require('@/assets/5.jpg')},
      ],
    };
  },
  methods:{
    imageLoad(){
      this.$nextTick(()=>{
        this.bannerHeight=this.$refs.bannerHeight[0].height
      })
    }
  },
  mounted() {
    this.imageLoad();
    window.addEventListener('resize',()=>{
      this.bannerHeight=this.$refs.bannerHeight[0].height
      this.imageLoad()
    },false)
  },
};
</script>

<style scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 100%;
  width: 100%;
  margin: 0;
}
.carousel_image_type{
  width: 100%;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>